package com.nlp.trie.viterbi;

import java.util.HashMap;
import java.util.Map.Entry;

public class ProbTable {
	HashMap<Object, Double> table;
	public ProbTable() {
		table = new HashMap<Object, Double>();
	}
	
	public void put(Object obj, double prob) {
		table.put(obj, prob);
	}
	
	public double get(Object obj) {
		Double prob = table.get(obj);
		return prob;
	}
	
	public void normalize() {
		double total = 0.0;
		for (Entry<Object, Double> entry : table.entrySet()) {
			total +=entry.getValue().doubleValue();
		}
		if (total == 0.0) {
			return;
		}
		
		for (Entry<Object, Double> entry : table.entrySet()) {
			Object k = entry.getKey();
			double prob = entry.getValue();
			table.put(k, prob/total);
		}
	}

}
